[SQL] Query returning more than one row with the same name

Posted by Neutralise on Stack Overflow See other posts from Stack Overflow or by Neutralise
Published on 2010-12-24T04:36:07Z Indexed on 2010/12/24 4:54 UTC
Read the original article Hit count: 161

Filed under:

I am having trouble with an SQL query returning more than one row with the same name, using this query:

SELECT * FROM People P JOIN SpecialityCombo C ON P.PERSONID = C.PERSONID JOIN Speciality S ON C.GROUPID = S.ID;

People contains information on each person, Specialty contains the names and ID of each specialty and SpecialityCombo contains information about the associations between People and their Speciality, namely each row has a PERSONID and a Speciality ID (trying to keep it normalised to some extent).

My query works in that it returns each Person and the name of their specialty, but it returns n rows for the number of specialitys they want, because each specialty returns the same row 'name'. What I want is it to return just one row containing each speciality. How can I do this?

© Stack Overflow or respective owner

Related posts about sql